package com.lyq.controller.deferred;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.async.DeferredResult;

/**
 * servlet 3.0
 * 返回之后，servlet线程将被释放，可用于其他连接；DeferredResult另外会有线程来进行结果处理，并setResult
 */
@RestController
@RequestMapping("/deferred")
public class DeferredController {
    private DeferredResult<String> deferredResult = new DeferredResult<>(300000L, "请求超时！");

    @GetMapping(value = "/get")
    public DeferredResult get() {
        return deferredResult;
    }

    @GetMapping(value = "/set")
    public String set() {
        deferredResult.setResult("success！");
        return "success";
    }
}
